import time
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver

class ForumPersonalCenter:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
        # 添加隐式等待
        self.driver.implicitly_wait(3)
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()

    # 个人中心验证界面信息测试
    def PersonalCenter(self):
        #验证个人中心界面中用户中心、我的账户文字和用户头像、用户名、昵称、邮箱电话等信息是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col-3.d-none.d-md-block.border-end > div > div > a")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_avatar")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_nickname")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > h3:nth-child(4)")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > h3:nth-child(7)")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > h3:nth-child(10)")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > h3:nth-child(13)")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > h3:nth-child(16)")
        # 截图验证
        ForumDriver.getScreeShot()

    #修改个人信息测试
    def InfoModify(self):
        #修改昵称 截图验证
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys("Neyma")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        ForumDriver.getScreeShot()
        #修改邮箱地址 截图验证
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").send_keys("2@qq.com")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        ForumDriver.getScreeShot()

        #修改电话号码 截图验证
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").send_keys("7777")
        time.sleep(10)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        ForumDriver.getScreeShot()

        #修改个人简介 截图验证
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").send_keys("hello world")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_remark").click()

        #修改密码 截图验证
        #修改失败
        #输入错误的原密码
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        ForumDriver.getScreeShot()
        #输入正确的原密码 新原密码和确认密码不同
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        ForumDriver.getScreeShot()

        #修改成功
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("1234")
        time.sleep(10)
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        time.sleep(3)
        #修改成功返回登录界面 截图验证
        ForumDriver.getScreeShot()

#创建center类对象
# center = ForumPersonalCenter()
# #个人中心测试
# center.PersonalCenter()
# #修改信息测试
# center.InfoModify()
